#include "CGround.h"


CGround::CGround(IrrlichtDevice* device)
{
	ISceneManager* smgr = device->getSceneManager();
	IVideoDriver* driver = device->getVideoDriver();

	ITerrainSceneNode* terrain = smgr->addTerrainSceneNode(L"data/terrain/heightmap.png", 0, -1,
		vector3df(0.f, 0.f, 0.f),	
		vector3df(0.f, 0.f, 0.f),	
		vector3df(16.f, 0.f, 16.f));

	terrain->setMaterialFlag(EMF_LIGHTING, false);

	terrain->setMaterialTexture(0, driver->getTexture(L"data/terrain/ground.tga"));
	terrain->scaleTexture(16.f);

	// Get terrain size
	aabbox3df boundingBox = terrain->getBoundingBox();
	vector3df* edge = new vector3df[8];
	boundingBox.getEdges(edge);

	size.X = edge[0].getDistanceFrom(edge[2]);
	size.Z = edge[0].getDistanceFrom(edge[4]);

	// Returns memory allocated by new
	delete[] edge;
	edge = NULL;
}


CGround::~CGround(void)
{
}


vector3df CGround::getSize(void)
{
	return size;
}